<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="okhttp3.*" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.concurrent.TimeUnit" %>
<%--流程退回调用QMS接口--%>
<%
    String url = "http://10.193.221.95:8080/jeecg-boot/srm/oa/processSpeed";
    out.println(">>>>>url=" + url+"<br/>");
    JSONObject dataJson = new JSONObject();
    dataJson.put("nodeCode", "12354");
    dataJson.put("nodeName", "张三 总经理,李四 会计");
    dataJson.put("nodeUser", "123322");
    dataJson.put("processId", "1231231");
    dataJson.put("status", "0");
    dataJson.put("type", "0");
    dataJson.put("attachment", "1231");
    dataJson.put("source", "srm");
    out.println(">>>>>>dataJson=" + dataJson+"<br/>");
    JSONObject resultJson = sendOKHttpRequest(url,dataJson.toJSONString());
    out.println(">>>>>测试接口>>>>>resultJson=" + resultJson+ "<br/>");
%>

<%!
    public static JSONObject sendOKHttpRequest(String curl,String params) {
        JSONObject resultJson = new JSONObject();
        String code = "fail";
        String message = "";
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .connectTimeout(60, TimeUnit.SECONDS)
                    .readTimeout(60, TimeUnit.SECONDS)
                    .writeTimeout(60, TimeUnit.SECONDS)
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, params);
            Request request = new Request.Builder()
                    .url(curl)
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
            String result = Util.null2String(response.body().string());
            if (!"".equals(result)) {
                resultJson = JSONObject.parseObject(result);
                code = "success";
            } else {
                message = "response result is null";
                code = response.code()+"";
            }
        } catch (Exception e) {
            message = "response timeout";
            e.printStackTrace();
        }
        resultJson.put("code", code);
        resultJson.put("message", message);
        return resultJson;
    }
%>




